<include file="Public/min-header" />
<link href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
<script src="__PUBLIC__/plugins/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<div class="wrapper">
	<style type="text/css">
		th{text-align: center;background: #eee;}
	</style>
    <include file="Public/breadcrumb"/>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	             <div class="box-header">
	             <div class="row">
  					<div class="col-md-10" style="width: 100%;">
						<div class="navbar navbar-default">
						        <form action="" id="search-form2" class="navbar-form form-inline" method="get">
									<?php
									if(session('fenbu_id')==0){
									?>
									<div class="form-group">
										<select name="fenbu_id" id="fenbu_id" class="input-sm" style="width:120px;">
											<option value="-1" >全部</option>
											<foreach name="fenbu_list" item="v">
												<option value="{$v['fenbu_id']}" <?php if(I('fenbu_id')==$v['fenbu_id']){ ?>selected="selected" <?php } ?>>
												{$v['fenbu_name']}
												</option>
											</foreach>
										</select>
									</div>
									<?php
									}else{
										echo '<input type="hidden" name="fenbu_id" id="fenbu_id" value="'.session('fenbu_id').'" />';
									}
									?>
						                                <div class="form-group">
						                                    <div class="input-group">
						                                        <input type="text" name="consignee" placeholder="商家/收货人/商铺名" id="input-member-id" class="input-sm form-control" style="width:150px;" value="{:I('consignee')}">
						                                    </div>
						                                </div>
						                                <div class="form-group">
						                                    <div class="input-group">
						                                        <input type="text" name="order_sn" placeholder="订单号搜索" id="input-order-id" class="input-sm form-control" style="width:150px;" value="{:I('order_sn')}">
						                                    </div>
						                                </div>
														<div class="form-group">
															<div class="input-group">
																<input type="text" name="biaoshi_xian" id="biaoshi_xian" placeholder="路线" id="input-b1" class="input-sm" value="{:I('biaoshi_xian')}" style="width:100px;">
															</div>
														</div>
						                                <div class="form-group">
						                                    <div class="input-group" style="width: 300px;margin-left: 15px;">
						                                      <div class="input-group-addon" style="width:45%;">
						                                       		时间  <i class="fa fa-calendar"></i>
						                                      </div>
						                                      <input type="text" class="form-control" name="timegap" value="{:I('timegap')}" id="start_time" autocomplete="off" style="width: 250px;">
						                                      </div>
						                                </div>


									<div class="form-group">
										<select name="type" id="type" class="input-sm" style="width:100px;">
											<if condition="$vo['type'] eq '0'">
												<?php
												 if(I("type")=="0"){
																	?>
												<option value="">类型</option>
												<option value="0" selected="selected">维修</option>
												<option value="1">换货商品</option>
												<?php
																}elseif(I("type")=="1"){
																?>
												<option value="">类型</option>
												<option value="0">维修</option>
												<option value="1"  selected="selected">换货商品</option>
												<?php
																}else{
																?>
												<option value="">类型</option>
												<option value="0">维修</option>
												<option value="1">换货商品</option>
												<?php
																}
																?>
										</select>
									</div>

									<div class="form-group">
									<select name="status" id="status" class="input-sm" style="width:100px;">
										<if condition="$vo['status'] eq '0'">
											<?php
												 if(I("status")=="0"){
																	?>
											<option value="">状态</option>
											<option value="0" selected="selected">进行中</option>
											<option value="1">已完成</option>
											<?php
																}elseif(I("status")=="1"){
																?>
											<option value="">状态</option>
											<option value="0">进行中</option>
											<option value="1"  selected="selected">已完成</option>
											<?php
																}else{
																?>
											<option value="">状态</option>
											<option value="0">进行中</option>
											<option value="1">已完成</option>
											<?php
																}
																?>
									</select>
								</div>




														<div class="form-group">
															<input class="btn btn-primary margin" type="submit" value="确定">
														</div>
						                                <div class="form-group">
						                                	<a href="/index.php?m=admin&c=Order&a=fix_edit_order" class="btn btn-primary margin">添加维修/换货单</a>
						                                </div>
						                             
														<div class="form-group">
															<button type="button" class="btn btn-default pull-right" id="daochu"><i class="fa fa-file-excel-o"></i>&nbsp;导出excel</button>
						                                </div>
						                            </form>
						                    </div>
                 	</div>
		  		 </div>
	             </div><!-- /.box-header -->
	             <div class="box-body" style="margin-top: -30px;">

	           	 <div class="row">
	            	<div class="col-sm-12">
		              <table id="list-table" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
		                 <thead>
		                   <tr role="row">
		                        <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);"></td>
							   <th class="sorting" align="center">ID</th>
                               <th class="sorting" align="center">单号</th>
                               <th class="sorting" align="center">备注</th>
							   <th class="sorting" align="center">商家</th>
							   <th class="sorting" align="center">买家</th>
			                   <th class="sorting" align="center">名称</th>
			                   <th class="sorting" align="center">单价</th>
			                   <th class="sorting" align="center">数量</th>
							   <th class="sorting" align="center">创建时间</th>
							   <th class="sorting" align="center">状态</th>
							   <th class="sorting" align="center">完成时间</th>
							   <th class="sorting" align="center">关联单号</th>
							   <th class="sorting" align="center">领取状态</th>
							   <th class="sorting" align="center">先补货</th>
							   <th class="sorting" align="center">操作</th>
		                   </tr>
		                 </thead>
						<tbody>
							
                         <foreach name="orderList" item="vo" key="k" >

                          <tr role="row" align="center" class="quhuo">
                            <td class="text-center">
                                <input type="checkbox" name="selected[]" value="{$vo['id']}">
                            </td>
							 <td>{$vo.id}</td>
                             <td><a href="javascript:" id="chakan" rel="{$vo.order_id}">{$vo.order_sn}</a></td>
                             <td>{$vo.remark}</td>
							 <td>{$vo.store_name}</td>
							 <td>{$vo.company}{$vo.bianshi_xian}</td>
                             <td>{$vo.goods_name}（{$vo.key_name}）</td>
							 <td>{$vo.member_goods_price}</td>
							 <td>{$vo.goods_num}</td>
		                     <td>{$vo.addtime|date='Y-m-d H:i',###}</td>
							 <td>
							 <if condition="$vo['status'] eq '1'">
								 <if condition="$vo['type'] eq '0'">
							 <span style="color: green">已维修</span>
								<else/>
									 <span style="color: green">已换货</span>
								 </if>
							 <else/>
								 <if condition="$vo['type'] eq '0'">
							 <span style="color: red">维修中</span>
									 <else/>
									 <span style="color: red">换货中</span>
								 </if>
							 </if>
							 </td>
                            <td style="color: royalblue;">{$vo.status_time}</td>
                            <td >{$vo.fix_sn}</td>
							  <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[is_receive] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('fix_goods','id','{$vo.id}','is_receive',this)"/></td>
							  
							  <td>
							      <img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[is_exchange] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('fix_goods','id','{$vo.id}','is_exchange',this)"/>
							  </td>
							  <td> 

								  <?php
							 	if($vo['status'] != 1){
							 ?>
								  <a href="JavaScript:;" id="return_del" rel="{$vo.id}" rev="{$vo.order_id}" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a>
								  <?php
							 }else{
							 ?>
								  <a href="JavaScript:;" id="fix_finish" class="btn btn-info" data-toggle="tooltip" >已完成</a>
								  <?php
							 }
							 ?>
							  </td>
		                   </tr>
		                  </foreach>
		                   </tbody>
		               </table>
	               </div>
	          </div>
              <div class="row">
              	    <div class="col-sm-6 text-left"></div>
                    <div class="col-sm-6 text-right">{$page}</div>		
              </div>
	          </div>
	        </div>
       	</div>
       </div>
   </section>
</div>
<script type="text/javascript">
$(document).ready(function() {
	$('#start_time').daterangepicker({
			format:"YYYY-MM-DD HH:mm",
			singleDatePicker: false,
			showDropdowns: true,
			minDate:'2021-01-01 00:00',
			maxDate:'2030-01-01 00:00',
			startDate:'{:date("Y-m-d")} 00:00',
	        showWeekNumbers: true,
	        timePicker: true,
	        timePickerIncrement: 1,
	        timePicker12Hour: false,
	        opens: 'right',
	        buttonClasses: ['btn btn-default'],
	        applyClass: 'btn-small btn-primary',
	        cancelClass: 'btn-small',
		    locale : {
	            applyLabel : '确定',
	            cancelLabel : '取消',
	            fromLabel : '起始时间',
	            toLabel : '结束时间',
	            customRangeLabel : '自定义',
	            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
	            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
	            firstDay : 1
	        }
	});
	$("#list-table #chakan").click(function(){
			var myrel=$(this).attr('rel');
			var myrul='/index.php/Admin/order/detail/order_id/'+myrel;//+myrel;
				layer.open({
				  type: 2,
				  title:'订单信息',
				  shadeClose: true, //点击遮罩关闭
				  skin: 'layui-layer-rim', //加上边框
				  area: ['920px', '620px'], //宽高
				  content: myrul
			})
	    });
	$("#list-table #return_del").click(function(){
		var id=$(this).attr('rel');
		var order_id=$(this).attr('rev');
		layer.confirm('您确定要删除这个退货单吗？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		  $.post("/index.php/Admin/order/fix_del",
		  {
		    id:id,
		    order_id:order_id
		  },
		  function(data,status){
			  data=JSON.parse(data);
			  if(data.code=='200'){
				  layer.msg(data.msg, {icon:6});
				  location.reload();
			  }
		  });
		});
	})

	$("#daochu").click(function(){
		var consignee=$("#input-member-id").val();
		var order_sn=$("#input-order-id").val();
		var add_time=$("#start_time").val();
		var status=$("#status").val();
		var b1=$("#b1").val();
		var type=$("#type").val();
		var fenbu_id=$("#fenbu_id").val();
		location.href="/index.php/Admin/order/export_fix?order_sn="+order_sn+"&consignee="+consignee+"&timegap="+add_time+"&status="+status+"&b1="+b1+"&type="+type+"&fenbu_id="+fenbu_id;;
	})
});

  //批量删除
    function quhuo() {

        //获取选中的文章
        layer.confirm('确认要批量取货吗？',function(index){
            var inputs = $('.quhuo input[type="checkbox"]:checked')
            console.log(inputs)
            var ids ="";
            $.each(inputs,function (k,v) {
                if (v.value != ""){
                    ids +=  v.value+",";
                }
            });
            console.log(ids)
            ids = ids.slice(0,-1);
            $.ajax({
                type: 'GET',
                data:{
                    id:ids
                },
                url:"{:U('Admin/order/batchpickup')}",
                dataType: 'json',
                success: function(data){
                    if (data.status>0){
                        layer.msg(data.msg,{icon:1,time:1000});
                        document.location.reload();
                    }else{
                        layer.msg(data.msg,{icon:6,time:1000});
                    }

                }
            });
        } ,function(index){

            layer.close(index);

            return false;// 取消

        })
    }


$("#list-table #return_play").click(function(){
	var id=$(this).attr('rel');
	var order_id=$(this).attr('rev');
	layer.confirm('您确定提交银行申请退款吗？', {
		btn: ['确定','取消'] //按钮
	}, function(){
		$.post("/index.php/Admin/order/return_play",
				{
					id:id,
					order_id:order_id
				},
				function(data,status){
					data=JSON.parse(data);
					if(data.code=='200'){
						layer.msg(data.msg, {icon:6});
						location.reload();
					}else{
						layer.msg(data.msg, {icon:5});
						location.reload();
					}
				});
	});
})

$("#list-table #check_play").click(function(){
	var id=$(this).attr('rel');
	var order_id=$(this).attr('rev');
	$.post("/index.php/Admin/order/check_return_play",
			{
				id:id,
				order_id:order_id
			},
			function(data,status){
				data=JSON.parse(data);
				if(data.code=='200'){
					layer.msg(data.msg, {icon:6});
					location.reload();
				}else{
					layer.msg(data.msg, {icon:5});
					location.reload();
				}
			});
})
</script>
</body>
</html>